//
//  MSDepartmentAttendanceCell.m
//  觅尚
//
//  Created by No.8 on 2019/3/29.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSMonthTongjiCell.h"

@implementation MSMonthTongjiCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    MSMonthTongjiCell * cell = [tableView dequeueReusableCellWithIdentifier:[MSMonthTongjiCell ID]];
    cell = [[MSMonthTongjiCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[MSMonthTongjiCell ID]];
    cell.backgroundColor = backgroundcolor;
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setMember];
        
    }
    return self;
}

- (void)setMember{
    /** 图片*/
    self.photoIMG = [[UIImageView alloc] initWithFrame:CGRectMake(60 * px, 20 * px, 100 * px, 100 * px)];
    self.photoIMG.image = [UIImage imageNamed:@"酒水数据"];
    self.photoIMG.layer.cornerRadius = 50 * px;
    self.photoIMG.layer.masksToBounds = YES;
    [self addSubview:self.photoIMG];
    
    
    /** 名称*/
    self.commodityLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth * 0.15, self.photoIMG.y, ScreenWidth * 0.3, self.photoIMG.height)];
    self.commodityLabel.textColor = [UIColor whiteColor];
    self.commodityLabel.text = @"李四";
    self.commodityLabel.textAlignment = NSTextAlignmentCenter;
    self.commodityLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [self addSubview:self.commodityLabel];
    
    
    /** 上班签到*/
    self.SigninLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth * 0.5, self.commodityLabel.y, self.commodityLabel.width, self.commodityLabel.height)];
    self.SigninLabel.textColor = self.commodityLabel.textColor;
    self.SigninLabel.text = @"10:00";
    self.SigninLabel.textAlignment = NSTextAlignmentCenter;
    self.SigninLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [self addSubview:self.SigninLabel];
    

    
    
    /** 状态*/
    self.clickLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth * 0.75, 10 * px, self.commodityLabel.width, 30 * px)];
    self.clickLabel.textColor = FontColor;
    self.clickLabel.text = @"正常";
    self.clickLabel.textAlignment = NSTextAlignmentCenter;
    self.clickLabel.font = [UIFont systemFontOfSize:SYRealValue(16 / 2)];
    [self addSubview:self.clickLabel];
    
    
    /** 状态*/
    self.stateLabel = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth * 0.75, self.commodityLabel.y, self.commodityLabel.width, self.commodityLabel.height)];
    [self.stateLabel setTitleColor:self.commodityLabel.textColor forState:UIControlStateNormal];
    //    self.stateLabel.text = @"正常";
    self.stateLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.stateLabel.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [self addSubview:self.stateLabel];
    
    
    self.LineView = [[UIView alloc] initWithFrame:CGRectMake(0, 140 * px - 1, ScreenWidth, 1)];
    self.LineView.backgroundColor = BackViewColor;
    [self addSubview:self.LineView];
    
}

- (void)setTongjiModel:(MSMonthTongjiModel *)tongjiModel{
    _tongjiModel = tongjiModel;
    [self.photoIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",tongjiModel.avatarUrl]] placeholderImage:[UIImage imageNamed:@"我的占位头像"]];
    
    self.commodityLabel.text = [NSString stringWithFormat:@"%@",tongjiModel.userName];
    
    
    self.SigninLabel.text = [NSString stringWithFormat:@"%@/%@",tongjiModel.userAttendCount,tongjiModel.userShouldArriveCount];
    
    
    if ([tongjiModel.attendanceState isEqualToString:@"2"]) {
        self.clickLabel.text = @"3天连续未签到";
        [self.stateLabel setTitle:@"处理" forState:UIControlStateNormal];
        [self.stateLabel setTitleColor:WYCRGBColor(90, 196, 176) forState:UIControlStateNormal];
        [self.stateLabel addTarget:self action:@selector(stateClick) forControlEvents:UIControlEventTouchUpInside];
    }else{
        self.clickLabel.hidden = YES;
        [self.stateLabel setTitle:@"正常" forState:UIControlStateNormal];
        [self.stateLabel setTitleColor:BackViewColor forState:UIControlStateNormal];
    }
    
}

- (void)stateClick{
    
    WYCLogFunc;
    if (self.ButtonDelegate && [self.ButtonDelegate respondsToSelector:@selector(ClickuserName:uid:avatarUrl:attendacneState:)]) {
        [self.ButtonDelegate ClickuserName:self.tongjiModel.userName uid:self.tongjiModel.uid avatarUrl:self.tongjiModel.avatarUrl attendacneState:self.tongjiModel.attendanceState];
    }
}
+(NSString *)ID{
    return @"cell";
}

@end
